
//
//  MYStatusBottomView.swift
//  NewMicroblog
//
//  Created by apple on 2016/10/26.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class MYStatusBottomView: UIView {
    
    var retweetButton: UIButton?
    var commentButton: UIButton?
    var unlikeButton: UIButton?
    
    var statusViewModel: MYStatusViewModel?{
        didSet{
            retweetButton?.setTitle(statusViewModel?.repostsCountStr, for: UIControlState.normal)
            commentButton?.setTitle(statusViewModel?.commentsCountStr, for: UIControlState.normal)
            unlikeButton?.setTitle(statusViewModel?.attitudesStr, for: UIControlState.normal)

    }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - 监听事件
    @objc private func buttonClick(){
        
    }
    
    // MARK: - 设置视图
    private func setupUI(){
        // 01 添加控件
        retweetButton = addChildButtons(imgName: "timeline_icon_retweet", title: "转发")
        commentButton = addChildButtons(imgName: "timeline_icon_comment", title: "评论")
        unlikeButton = addChildButtons(imgName: "timeline_icon_unlike", title: "赞")
        
        let line1 = addChildLines()
        let line2 = addChildLines()
        // 02 添加约束
        
        retweetButton!.snp_makeConstraints { (make) in
            make.top.left.bottom.equalTo(self)
            make.width.equalTo(commentButton!)
        }
        
        commentButton!.snp_makeConstraints { (make) in
            make.top.bottom.equalTo(self)
            make.left.equalTo(retweetButton!.snp_right)
            make.width.equalTo(unlikeButton!)
        }
        
        unlikeButton!.snp_makeConstraints { (make) in
            make.top.bottom.right.equalTo(self)
            make.left.equalTo(commentButton!.snp_right)
        }
        
        line1.snp_makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.centerX.equalTo(retweetButton!.snp_right)
        }
        
        line2.snp_makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.centerX.equalTo(commentButton!.snp_right)
        }
        
    }

    
    
    // 添加按钮公共方法
    func addChildButtons(imgName: String, title: String) -> UIButton{
        //创建 button
        let button = UIButton(setImage: imgName, title: title, tagart: self, action: #selector(buttonClick))
        // 这是背景图
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), for: UIControlState.normal)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), for: UIControlState.highlighted)
        // 添加 button
        addSubview(button)
        return button
    }
    // 添加分割线
    func addChildLines() -> UIImageView{
        let img = UIImageView(imageName: "timeline_card_bottom_line"
        )
        // 添加控件
        addSubview(img)
        return img
    }
    

}
